home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / ggraph / RCS / ggraph.c,v < prev    next >
Text File  |  1991-10-28  |  6KB  |  230 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    pmchen:1.2; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     89.06.15.22.58.02;  author douglis;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     89.05.15.22.58.01;  author douglis;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @program to produce gremlin graphs
  22. @
  23.  
  24.  
  25. 1.2
  26. log
  27. @i bracketed an if, but i don't know why i made this change!
  28. @
  29. text
  30. @#include <stdio.h>
  31. #include <errno.h>
  32. #include <strings.h>
  33. #include <math.h>
  34. #include <ctype.h>
  35. #include "ggraph.h"
  36. #include "ggraphdefs.h"
  37.  
  38. int interact;            /* switch for interactive mode */
  39. main (argc, argv)
  40. char   *argv[];
  41. int     argc;
  42. {
  43. FILE *infile;            /* input file */
  44.  
  45.     if(argc == 3) {        /* scan arguments */
  46.       if(!strcmp(argv[1], "-d")){
  47.     debug++;
  48.     argc--, argv++;
  49.       }
  50.       if(!strcmp(argv[1], "-i")){
  51.     interact++;
  52.     argc--, argv++;
  53.       }
  54.     }
  55.     if (argc == 1) {
  56.     infile = stdin;
  57.     fflush(stdin);
  58.     outfile = stdout;
  59.     }else
  60.     if ((infile = fopen (argv[1], "r")) == NULL) {/* open input file */
  61.     perror ("can't open input file");
  62.     exit (-1);
  63.     }
  64.     if ((outfile = fopen (argv[2], "w")) != NULL)/* open output file */
  65.     setbuf (outfile, NULL);    /* no buffering */
  66.     if(debug)fprintf (stderr, "Reading file\n");
  67.     readcmds (infile);        /* read graph commands */
  68.     if(debug)fprintf (stderr, "Graph program done\n");
  69.     exit (0);
  70. }
  71.  
  72. /****************************************************************
  73.  *                                *
  74.  *    gremlinheader - write header for gremlin file        *
  75.  *                                *
  76.  ****************************************************************/
  77. gremlinheader () {
  78.     if(version == SUN_GREMLIN)
  79.       fprintf (outfile, "%s\n%d %4.1f %4.1f\n",
  80.         sfirstline, VERTICAL, cg.xorigin, cg.yorigin);
  81.     else
  82.       fprintf (outfile, "%s\n%d %4.1f %4.1f\n",
  83.         firstline, VERTICAL, cg.xorigin, cg.yorigin);
  84. }
  85.  
  86. /****************************************************************
  87.  *                                *
  88.  *    drawctext - write some text                 *
  89.  *            x, y - point to draw text at        *
  90.  *            font - font to use                *
  91.  *            size - size of text                *
  92.  *            string - text to draw            *
  93.  *            just - justification to use            *
  94.  *                                *
  95.  ****************************************************************/
  96. drawctext (x, y, font, size, string, just)
  97. int     font;
  98. int     size;
  99. float   x,
  100.         y;
  101. char   *string;
  102. int     just;
  103. {
  104.     float pos_x, pos_y;
  105.     int length;
  106.  
  107.     length = strlen(string) * xcharsz[size];
  108.  
  109.     switch (just) {
  110.     case BOTLEFT_TEXT:
  111.         pos_x = x;
  112.         pos_y = y;
  113.     case BOTCENTER_TEXT:
  114.         pos_x = x - (length >> 1);
  115.         pos_y = y;
  116.         break;
  117.     case BOTRIGHT_TEXT:
  118.         pos_x = x - length;
  119.         pos_y = y;
  120.         break;
  121.     case CENTERLEFT_TEXT:
  122.         pos_x = x;
  123.         pos_y = y - (ycharsz[size] >> 1);
  124.         break;
  125.     case CENTERCENTER_TEXT:
  126.         pos_x = x - (length >> 1);
  127.         pos_y = y - (ycharsz[size] >> 1);
  128.         break;
  129.     case CENTERRIGHT_TEXT:
  130.         pos_x = x - length;
  131.         pos_y = y - (ycharsz[size] >> 1);
  132.         break;
  133.     case TOPLEFT_TEXT:
  134.         pos_x = x;
  135.         pos_y = y + descenders[size] - ycharsz[size];
  136.         break;
  137.     case TOPCENTER_TEXT:
  138.         pos_x = x - (length >> 1);
  139.         pos_y = y + descenders[size] - ycharsz[size];
  140.         break;
  141.     case TOPRIGHT_TEXT:
  142.         pos_x = x - length;
  143.         pos_y = y + descenders[size] - ycharsz[size];
  144.         break;
  145.     }
  146.  
  147.     if (version == SUN_GREMLIN)
  148.     fprintf(outfile, "%s\n", justify_names[just]);
  149.     else
  150.     fprintf(outfile, "%d\n", just);
  151.  
  152.     fprintf(outfile, "%3.2f %3.2f\n", x, y);
  153.     fprintf(outfile, "%3.2f %3.2f\n", pos_x, pos_y);
  154.     fprintf(outfile, "%3.2f %3.2f\n", pos_x + (length >> 1), pos_y);
  155.     fprintf(outfile, "%3.2f %3.2f\n", pos_x + length, pos_y);
  156.  
  157.     fprintf(outfile, (version == SUN_GREMLIN) ? "*\n" : "-1.00 -1.00\n");
  158.     fprintf (outfile, "%d %d\n%d %s\n", font, size, strlen (string), string);
  159.     return(GR_OK);
  160. }
  161.  
  162. /****************************************************************
  163.  *                                *
  164.  *    drawvtext - write some vertical text            *
  165.  *            x, y - point to draw text at        *
  166.  *            font - font to use                *
  167.  *            size - size of text                *
  168.  *            string - text to draw            *
  169.  *            charh - height per character to use        *
  170.  *                                *
  171.  ****************************************************************/
  172. drawvtext (x, y, font, size, string, charh)
  173. int     font;
  174. int     size;
  175. float   x, y;
  176. char   *string;
  177. int   charh;
  178. {
  179.     char *cp;            /* pointer into string */
  180.  
  181.     cp = string;
  182.     while(*cp){
  183.     if (version == SUN_GREMLIN)
  184.     fprintf(outfile, "%s\n", justify_names[TOPCENTER_TEXT]);
  185.     else
  186.     fprintf(outfile, "%d\n",  TOPCENTER_TEXT);
  187.     fprintf (outfile, "%4.1f %4.1f\n", x, y);
  188.     fprintf (outfile, "%4.1f %4.1f\n", x, y);
  189.     fprintf (outfile, "%4.1f %4.1f\n", x + 5.0, y);
  190.     fprintf (outfile, "%4.1f %4.1f\n", x + 10.0, y);
  191.     fprintf(outfile, (version == SUN_GREMLIN) ? "*\n" : "-1.00 -1.00\n");
  192.     fprintf (outfile, "%d %d\n%d %c\n", font, size, 1, *cp);
  193.     ++cp;
  194.     y = y - charh;
  195.     }
  196. }
  197.  
  198. /****************************************************************
  199.  *                                *
  200.  *    drawline - write a line                 *
  201.  *            x1, y1 - starting point            *
  202.  *            x1, y1 - ending point            *
  203.  *                                *
  204.  ****************************************************************/
  205. drawline (brush, x1, y1, x2, y2)
  206. int     brush;
  207. float   x1, x2, y1, y2;
  208. {
  209.     if(version == SUN_GREMLIN)
  210.       fprintf (outfile, "VECTOR\n%4.1f %4.1f\n%4.1f %4.1f\n", x1, y1, x2, y2);
  211.     else
  212.       fprintf (outfile, "%d\n%4.1f %4.1f\n%4.1f %4.1f\n", LINE, x1, y1, x2, y2);
  213.     fprintf(outfile, (version == SUN_GREMLIN) ? "*\n" : "-1.00 -1.00\n");
  214.     fprintf (outfile, "%d %d\n%d\n", brush, 0, 0);
  215. }
  216.  
  217. @
  218.  
  219.  
  220. 1.1
  221. log
  222. @Initial revision
  223. @
  224. text
  225. @d16 1
  226. a16 1
  227.     if(argc == 3)        /* scan arguments */
  228. d25 1
  229. @
  230.